home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / c / rel_u370aix.c < prev    next >
C/C++ Source or Header  |  1990-11-20  |  2KB  |  95 lines

  1. /* Copyright William Schelter. All rights reserved.  This file does
  2. the low level relocation which tends to be very system dependent.
  3. It is included by the file sfasl.c
  4. */
  5.  
  6. print_rel(rel,sym)
  7. struct syment *sym;
  8.  struct reloc *rel;
  9. {char tem[10];
  10.   printf(" (name = %s)",SYM_NAME(sym));
  11.  printf("{r_type=%d",rel->r_type);
  12.  fflush(stdout);
  13. }
  14.  
  15.  
  16. #ifdef DEBUG
  17.  
  18. #define describe_sym describe_sym1
  19. describe_sym1(n)
  20. int n;
  21. {char *str;
  22.  char tem[9];
  23.  struct syment *sym;
  24.  sym= &symbol_table[n];
  25.  str = SYM_NAME(sym);
  26.  if (debug == 0)  return 1;
  27.  printf ("sym-index = %d table entry at %x",n,&symbol_table[n]);
  28.  printf("symbol is (%s):\nsymbol_table[n]._n._n_name %d\nsymbol_table[n]._n._n_n._n_zeroes %d\nsymbol_table[n]._n._n_n._n_offset %d\nsymbol_table[n]._n._n_nptr[0] %d\nsymbol_table[n]._n._n_nptr[n] %d\nsymbol_table[n].n_value %d\nsymbol_table[n].n_scnum %d " 
  29. "\nsymbol_table[n].n_type %d\nsymbol_table[n].n_sclass %d\nsymbol_table[n].n_numaux %d", 
  30.     symbol_table[n]._n._n_name,
  31.     symbol_table[n]._n._n_n._n_zeroes ,
  32.     symbol_table[n]._n._n_n._n_offset ,
  33.     symbol_table[n]._n._n_nptr[0] ,
  34.     symbol_table[n]._n._n_nptr[1] ,
  35.     symbol_table[n].n_value ,
  36.     symbol_table[n].n_scnum ,
  37.     symbol_table[n].n_type ,
  38.     symbol_table[n].n_sclass ,
  39.     symbol_table[n].n_numaux );
  40. }
  41.  
  42. #endif 
  43.  
  44. #define LONG_AT_ADDR(p)  *((unsigned int *)p)
  45. #define STORE_LONG(p,val) (*((unsigned int *)p)) = (val)
  46.  
  47.  
  48.  
  49.  
  50. relocate()
  51. {
  52.   char *where;
  53.   int old_val,new_val;
  54. #ifdef DEBUG
  55.   if (debug)
  56.     {print_rel(&relocation_info,&symbol_table[relocation_info.r_symndx]);
  57.      describe_sym(relocation_info.r_symndx);}
  58. #endif
  59.   where = the_start + relocation_info.r_vaddr;
  60.   dprintf (where has %x , *where);
  61.   dprintf(   at %x -->, where );
  62.   
  63.   if (relocation_info.r_type == R_ABS)
  64.     { dprintf( r_abs ,0);  return; }
  65.   old_val = LONG_AT_ADDR(where);
  66.   switch(relocation_info.r_type)
  67.     { int *q;
  68.       
  69.     case R_RELLONG:  
  70.     case R_DIR32:
  71.       new_val= old_val + symbol_table[relocation_info.r_symndx].n_value;
  72.       dprintf(new val r_dir32 %x , new_val);
  73.       STORE_LONG(where,new_val);
  74.       break;
  75.  
  76.     case R_PCRLONG:
  77.  
  78.       new_val = old_val - (int) start_address +
  79.     symbol_table[relocation_info.r_symndx].n_value;
  80.       dprintf( r_pcrlong new value = %x , new_val)
  81.       STORE_LONG(where,new_val);
  82.       break;
  83.  
  84.     default:
  85.       fprintf(stderr, "%d: unsupported relocation type.",
  86.           relocation_info.r_type);
  87.       FEerror("The relocation type was unknown",0,0);
  88.     }
  89.  
  90. }
  91.  
  92.  
  93.  
  94.  
  95.